<?
/**
 * Copyright 2008 Melange.
 *
 * This file is part of Melange CMS
 *
 * @package cms
 *
 */


/**
 * Requirements
 */
require_once("mvc/action/ActionForm.php");
require_once("mvc/action/ActionMessage.php");
require_once("mvc/action/ActionMessages.php");
require_once("cms/image/om/TinyImage.php");



/**
 * BaseImageForm Class
 *
 * @category    Melange CMS
 * @package     cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class BaseImageForm extends ActionForm {


    // ----------------------------------------------------- Instance Variables


    /**
     * tinyImage
     *
     * @var TinyImage 
     */
    protected $tinyImage;


    /**
     * formImage
     *
     * @var mixed 
     */
    protected $formImage;


    /**
     * path
     *
     * @var mixed 
     */
    protected $path;


    /**
     * resize
     *
     * @var mixed 
     */
    protected $resize;


    // ----------------------------------------------------------- Constructors


    /**
     * Construct new BaseImageForm
     */
    public function __construct() {
        $this->tinyImage = new TinyImage();
        $this->formImage = null;
        $this->path = null;
        $this->resize = null;
    }


    // ------------------------------------------------------------- Properties


    /**
     * Get TinyImage
     *
     * @return TinyImage 
     */
    public function getTinyImage() {
        return $this->tinyImage;
    }


    /**
     * Set TinyImage
     *
     * @param TinyImage  tinyImage
     */
    public function setTinyImage(TinyImage $tinyImage) {
        $this->tinyImage = $tinyImage;
    }


    /**
     * Get FormImage
     *
     * @return mixed 
     */
    public function getFormImage() {
        return $this->formImage;
    }


    /**
     * Set FormImage
     *
     * @param mixed  formImage
     */
    public function setFormImage($formImage) {
        $this->formImage = $formImage;
    }


    /**
     * Get Path
     *
     * @return mixed 
     */
    public function getPath() {
        return $this->path;
    }


    /**
     * Set Path
     *
     * @param mixed  path
     */
    public function setPath($path) {
        $this->path = $path;
    }


    /**
     * Get Resize
     *
     * @return mixed 
     */
    public function getResize() {
        return $this->resize;
    }


    /**
     * Set Resize
     *
     * @param mixed  resize
     */
    public function setResize($resize) {
        $this->resize = $resize;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Validate this form
     *
     * @return array $errors
     */
    public function validate() {

        $errors = new ActionMessages();

        global $ALLOWABLE_IMAGES;
        if(!is_null($this->getFormImage()) && isset($this->formImage["size"]) && $this->formImage["size"] > 0 && !array_key_exists($this->formImage["type"], $ALLOWABLE_IMAGES))
            $errors->add("formImage",
                new ActionMessage("errors.image", true, new ActionMessage("prompt.image", true)));

        if(is_null($this->getResize()) || strlen($this->getResize()) == 0)
            $errors->add("resize",
                new ActionMessage("errors.required", true, new ActionMessage("prompt.resize", true)));


        return $errors;
    }

}
?>